#  Project: War Time Military Service Can Affect Partisan Preferences
#  Last updated: November 8,2022
#  Purpose: Create main Figures and Tables for Paper
#  Outputs: data/ines_77_2019.csv"
#  Machine: Chagai's macbook pro

#Load Packages------
library("tidyverse")
library("ggplot2")
library("stargazer")
library("xtable")
library("texreg")
library("readstata13")
library("estimatr")
library("naniar")
library("lfe")
library("multiwayvcov")
library("lmtest")
library("rdrobust")
library("rddensity")
library("sjmisc")
library("rdd")



#Read Data------
ines_master <- read.csv("data_for_analyses/ines_77_2019.csv") %>% 
  filter(.,
         aliya_after_73 !=1,
         age_in_73 < 74)
ines_master_olim <- read.csv("data_for_analyses/ines_77_2019.csv")# data including post 1973 immigrants

#Table A1----
# Create over-view of N per Wave

survey_year <- ines_master_olim %>% 
  dplyr::select(.,
                c(election_year)) %>% 
  mutate(.,
         Wave = case_when(
           election_year == 1981.1 ~ "1981B",
           election_year == 1981.2 ~ "1981C",
           election_year == 1988.1 ~ "1988B"
         ),
         Wave = ifelse(is.na(Wave),election_year, Wave)) %>% 
  group_by(., Wave) %>% 
  summarise(Observatiosn = n()) 

stargazer(as.data.frame(survey_year),
          summary = FALSE, rownames = T,
          title = "Observations Per Wave",
          label = "tab:obs_wave",
          font.size = "small",
          style = "qje",
          header=FALSE, type='latex',
          notes.append = F,
          notes.align = "l")

#Table A2-----
# Create Descriptive Stats
ines_master_olim <- ines_master_olim %>% 
  mutate(.,
         male = case_when(
           Sex == "male" ~ 1,
           Sex == "female" ~ 0),
         education = case_when(
           edu == "Less then HS" ~ 0,
           edu == "HS" ~ 1,
           edu == "Academic" ~ 2
         ),
         religiosity = case_when(
           relig == "Secular" ~ 0,
           relig == "Traditional" ~ 1, 
           relig == "Relig" ~ 2, 
           relig == "V. Relig" ~ 3 
         ))

disc_table <- ines_master_olim %>% 
  dplyr::select(.,
                c(age_in_73, vote_labor, vote_likud, undecide, no_vote, 
                  male, education, religiosity, ashkenazi,
                  ideology_7, right_wing, left_wing, 
                  labor_sec, war_over_peace,
                  spending, rooms_hh, ppl_hh))

stargazer(as.data.frame(disc_table),
          covariate.labels = c("Age 1973", "Vote Labor",  "Vote Likud", "Undecided", "No Vote", 
                               "Male", "Education", "Religiosity", 
                               "Ashkenazi", "Ideology", "Right Wing", "Left Wing",
                               "Labor Security", "War over Peace",
                               "HH Spending", "Rooms in HH", "People in HH"),
          title = "Descriptive Statistics",
          label = "tab:dsc",
          font.size = "small",
          style = "qje",
          omit.summary.stat = c("p25", "p75"),
          header=FALSE, type='latex',
          notes = c("Labor Security is a variable taking the value of 1, if a respondent believes",
                    "that the Labor party is best suited to handle security issues. Labor Economics",
                    "is a variable taking the value of 1, if a respondent believes that the Labor ",
                    "party is best suited to handle economic issues. War over Peace is a variable",
                    "taking the value of 1, if a respondent believes that the best way to protect",
                    "Israel is to prepare for war."),
          notes.append = F,
          notes.align = "l")



#Figure A1-------
ines_master %>% 
  mutate(.,
         election_year1 = case_when(
           election_year == 1981.1 ~ 1981,
           election_year == 1981.2 ~ 1981,
           election_year == 1988.1 ~ 1988,
           election_year == 1999.1 ~ 1999 ),
         election_year1 = ifelse(is.na(election_year1), election_year,election_year1)) %>% 
  ggplot(., aes(age_in_73, fill = as.factor(election_year1))) +
  geom_bar()+
  labs(x = "Age in 1973",
       y = "Count",
       fill = "Survey Year") +
  theme(panel.grid.major = element_blank(), 
        axis.text.x = element_text(size = 12),
        plot.caption = element_text(size = 10, family = "Times",hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))


#Figure A2------
margin_dens <- rddensity(ines_master$age_in_73, massPoints=FALSE, c =18,
                         regularize = F)
rdplotdensity(margin_dens, ines_master$age_in_73,
              alpha = 0.5,
              #  bwselect = "mse-dpi",
              # bwselect = "mse-rot",
              CIuniform = T,
              #hist = T,
              #type = "points",
              lcol = c("dodgerblue4", "firebrick4"),
              histFillCol = "gray20",
              xlabel = "Age in 1973",
              ylabel = "Proportion") 


#Figure A3-------
# Create Placebo Models

labor_m1 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 17, p = 1)
summary(labor_m1)

labor_m2 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 16, p = 1)
summary(labor_m2)

labor_m3 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 15, p = 1)
summary(labor_m3)

labor_m4 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 14, p = 1)
summary(labor_m4)

labor_m5 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 13, p = 1)
summary(labor_m5)

labor_m6 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 12, p = 1)
summary(labor_m6)

labor_m7 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 11, p = 1)
summary(labor_m7)

labor_m8 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 10, p = 1)
summary(labor_m8)

labor_m9 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 9, p = 1)
summary(labor_m9)

labor_m10 <- rdrobust(ines_master$vote_labor, 
                      ines_master$age_in_73,
                      c = 8, p = 1)
summary(labor_m10)


labor_1 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 19, p = 1)
summary(labor_1)

labor_2 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 20, p = 1)
summary(labor_2)

labor_3 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 21, p = 1)
summary(labor_3)

labor_4 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 22, p = 1)
summary(labor_4)


labor_5 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 23, p = 1)
summary(labor_5)


labor_6 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 24, p = 1)
summary(labor_6)

labor_7 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 25, p = 1)
summary(labor_7)

labor_8 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 26, p = 1)
summary(labor_8)

labor_9 <- rdrobust(ines_master$vote_labor, 
                    ines_master$age_in_73,
                    c = 27, p = 1)
summary(labor_9)

labor_10 <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 28, p = 1)
summary(labor_10)

labor <- rdrobust(ines_master$vote_labor, 
                  ines_master$age_in_73,
                  c = 18, p = 1)


# Create Placebo dataframe

placebo <- rbind(cbind(labor_m1$coef, labor_m1$ci, labor_m1$c),
                 cbind(labor_m2$coef, labor_m2$ci, labor_m2$c),
                 cbind(labor_m3$coef, labor_m3$ci, labor_m3$c),
                 cbind(labor_m4$coef, labor_m4$ci, labor_m4$c),
                 cbind(labor_m5$coef, labor_m5$ci, labor_m5$c),
                 cbind(labor_m6$coef, labor_m6$ci, labor_m6$c),
                 cbind(labor_m7$coef, labor_m7$ci, labor_m7$c),
                 cbind(labor_m8$coef, labor_m8$ci, labor_m8$c),
                 cbind(labor_m9$coef, labor_m9$ci, labor_m9$c),
                 cbind(labor_m10$coef, labor_m10$ci, labor_m10$c),
                 cbind(labor_1$coef, labor_1$ci, labor_1$c),
                 cbind(labor_2$coef, labor_2$ci, labor_2$c),
                 cbind(labor_3$coef, labor_3$ci, labor_3$c),
                 cbind(labor_4$coef, labor_4$ci, labor_4$c),
                 cbind(labor_5$coef, labor_5$ci, labor_5$c),
                 cbind(labor_6$coef, labor_6$ci, labor_6$c),
                 cbind(labor_7$coef, labor_7$ci, labor_7$c),
                 cbind(labor_8$coef, labor_8$ci, labor_8$c),
                 cbind(labor_9$coef, labor_9$ci, labor_9$c),
                 cbind(labor_10$coef, labor_10$ci, labor_10$c),
                 cbind(labor$coef, labor$ci, labor$c)) 
placebo <- as.data.frame(placebo) %>% 
  slice(seq(3,63,3)) %>% 
  rename(.,
         low = "CI Lower",
         high = "CI Upper")



# Plot Placebo

ggplot(placebo, aes(x = as.factor(V4), y = Coeff)) +
  geom_hline(yintercept = 0, color = "gray50", linetype = 2, size = 0.2) +
  geom_pointrange(aes(ymin = low, ymax = high), color = "dodgerblue4") +
  ylim(-.15,.15)+
  annotate("rect", xmin = 10.5, xmax = 11.5, ymin = -.15, ymax = .15,
           alpha = .2, fill = "firebrick2") +
  annotate("rect", xmin = 14.5, xmax = 15.5, ymin = -.15, ymax = .15,
           alpha = .2, fill = "firebrick2") +
  scale_fill_manual(values =  c("dodgerblue2")) +
  labs(x = "Age of RDD Cutoff",
       y = "RD Effect on Support for Labor") +
  theme(panel.grid.major = element_blank(), 
        axis.text.x = element_text(size = 12),
        plot.caption = element_text(size = 10, family = "Times",hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))



#Figure A4------
labor_m50 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 50, p = 1)
summary(labor_m50)

labor_m51 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 51, p = 1)
summary(labor_m51)

labor_m52 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 52, p = 1)
summary(labor_m52)

labor_m53 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 53, p = 1)
summary(labor_m53)

labor_m54 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 54, p = 1)
summary(labor_m54)

labor_m55 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 55, p = 1)
summary(labor_m55)

labor_m56 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 56, p = 1)
summary(labor_m56)

labor_m57 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 57, p = 1)
summary(labor_m57)

labor_m58 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 58, p = 1)
summary(labor_m58)

labor_m59 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 59, p = 1)
summary(labor_m59)


labor_m60 <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                      ines_master$age_in_73[ines_master$Sex=="male"],
                      c = 60, p = 1)
summary(labor_m60)

# Create Placebo dataframe

placebo2 <- rbind(cbind(labor_m50$coef, labor_m50$ci, labor_m50$c),
                  cbind(labor_m51$coef, labor_m51$ci, labor_m51$c),
                  cbind(labor_m52$coef, labor_m52$ci, labor_m52$c),
                  cbind(labor_m53$coef, labor_m53$ci, labor_m53$c),
                  cbind(labor_m54$coef, labor_m54$ci, labor_m54$c),
                  cbind(labor_m55$coef, labor_m55$ci, labor_m55$c),
                  cbind(labor_m56$coef, labor_m56$ci, labor_m56$c),
                  cbind(labor_m57$coef, labor_m57$ci, labor_m57$c),
                  cbind(labor_m58$coef, labor_m58$ci, labor_m58$c),
                  cbind(labor_m59$coef, labor_m59$ci, labor_m59$c),
                  cbind(labor_m60$coef, labor_m60$ci, labor_m60$c)) 
placebo2 <- as.data.frame(placebo2) %>% 
  slice(seq(3,33,3)) %>% 
  rename(.,
         low = "CI Lower",
         high = "CI Upper")



# Plot Placebo

ggplot(placebo2, aes(x = as.factor(V4), y = Coeff)) +
  geom_hline(yintercept = 0, color = "gray50", linetype = 2, size = 0.2) +
  geom_pointrange(aes(ymin = low, ymax = high), color = "dodgerblue4") +
  #ylim(-.15,.15)+
  annotate("rect", xmin = 4.5, xmax = 5.5, ymin = -.55, ymax = .55,
           alpha = .2, fill = "firebrick2") +
  scale_fill_manual(values =  c("dodgerblue2")) +
  labs(x = "Age of RDD Cutoff",
       y = "RD Effect on Support for Labor") +
  theme(panel.grid.major = element_blank(), 
        axis.text.x = element_text(size = 12),
        plot.caption = element_text(size = 10, family = "Times",hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))



# Table A3------
#recode demographics
ines_master <- ines_master %>% 
  mutate(.,
         edu_count = case_when(
           edu == "Less then HS" ~ 0,
           edu == "HS" ~ 1,
           edu == "Academic" ~ 3),
         relig_count = case_when(
           relig == "Secular" ~ 0,
           relig == "Traditional" ~ 1,
           relig == "Relig" ~ 2,
           relig == "V. Relig" ~ 3)) 



edu <- rdrobust(ines_master$edu_count, 
                ines_master$age_in_73,
                c = 18, p = 1)
summary(edu)

relig <- rdrobust(ines_master$relig_count, 
                  ines_master$age_in_73,
                  c = 18, p = 1)
summary(relig)



ashk <- rdrobust(ines_master$ashkenazi, 
                 ines_master$age_in_73,
                 c = 18, p = 1)
summary(ashk)







# Create Data frame for Table
balance <- rbind(
  cbind(round(edu$coef,3), round(edu$se,3), 
        rbind(round(edu$bws[1,1]),round(edu$bws[1,1]),round(edu$bws[1,1])), 
        rbind(edu$p,edu$p,edu$p), sum(edu$N), round(edu$ci,3)),
  cbind(round(relig$coef,3), round(relig$se,3), 
        rbind(round(relig$bws[1,1]),round(relig$bws[1,1]),round(relig$bws[1,1])), 
        rbind(relig$p,relig$p,relig$p), sum(relig$N), round(relig$ci,3)),
  cbind(round(ashk$coef,3), round(ashk$se,3), 
        rbind(round(ashk$bws[1,1]),round(ashk$bws[1,1]),round(ashk$bws[1,1])), 
        rbind(ashk$p,ashk$p,ashk$p), sum(ashk$N), round(ashk$ci,3)))

bal_df <- as.data.frame(balance) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Obs." = "V5") %>% 
  slice(3,6,9,12) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "Education",
           rowname == "Robust.1" ~ "Religiosity",
           rowname == "Robust.2" ~ "Ashkenazi"
         ),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

bal_df<- rotate_df(bal_df, cn =T)

bal_df[2,] <- paste0("(", format(unlist(bal_df[2,])),")")  
rownames(bal_df)[rownames(bal_df) == "Estimate"] <- ""
rownames(bal_df)[rownames(bal_df) == "SE"] <- " "

stargazer(bal_df,
          summary = FALSE, rownames = T,
          title = "Demographic Differences Around the Discontinuity",
          label = "tab:bal",
          # column.sep.width = "0.5",
          style = "ajps",
          header=FALSE, 
          font.size = "small",
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal",
                    " bandwidths, and a triangular kernal. Robust",
                    "standard errors in parentheses."),
          notes.append = F,
          notes.align = "l")


# Table A4-----
labor_male <- rdrobust(ines_master$vote_labor[ines_master$Sex=="male"], 
                       ines_master$age_in_73[ines_master$Sex=="male"],
                       c = 18, p = 1)
summary(labor_male)

labor_female <- rdrobust(ines_master$vote_labor[ines_master$Sex=="female"], 
                         ines_master$age_in_73[ines_master$Sex=="female"],
                         c = 18, p = 1)
summary(labor_female)

labor_immig <- rdrobust(ines_master_olim$vote_labor[ines_master_olim$aliya_after_73 == 1], 
                        ines_master_olim$age_in_73[ines_master_olim$aliya_after_73 == 1],
                        c = 18, p = 1)
summary(labor_immig)


undecided_male <- rdrobust(ines_master$undecide[ines_master$Sex=="male"], 
                           ines_master$age_in_73[ines_master$Sex=="male"],
                           c = 18, p = 1)
summary(undecided_male)

undecided_female <- rdrobust(ines_master$undecide[ines_master$Sex=="female"], 
                             ines_master$age_in_73[ines_master$Sex=="female"],
                             c = 18, p = 1)
summary(undecided_female)


undecided_immig <- rdrobust(ines_master$undecide[ines_master_olim$aliya_after_73 == 1], 
                            ines_master$age_in_73[ines_master_olim$aliya_after_73 == 1],
                            c = 18, p = 1)
summary(labor_immig)

labor <- rdrobust(ines_master$vote_labor, 
                  ines_master$age_in_73,
                  c = 18, p = 1)
summary(labor)

likud <- rdrobust(ines_master$vote_likud, 
                  ines_master$age_in_73,
                  c = 18, p = 1)
summary(likud)


undecided <- rdrobust(ines_master$undecide, 
                      ines_master$age_in_73,
                      c = 18, p = 1)
summary(undecided)


turnout <- rdrobust(ines_master$no_vote, 
                    ines_master$age_in_73,
                    c = 18, p = 1)
summary(turnout)



# Create Data frame for Table
main_result_mf <- rbind(
  cbind(round(labor$coef,3), round(labor$se,3), 
        rbind(round(labor$bws[1,1]),round(labor$bws[1,1]),round(labor$bws[1,1])), 
        rbind(labor$p,labor$p,labor$p), "Full",sum(labor$N), round(labor$ci,3)),
  cbind(round(labor_male$coef,3), round(labor_male$se,3), 
        rbind(round(labor_male$bws[1,1]),round(labor_male$bws[1,1]),round(labor_male$bws[1,1])), 
        rbind(labor_male$p,labor_male$p,labor_male$p), "Male", sum(labor_male$N), round(labor_male$ci,3)),
  cbind(round(labor_female$coef,3), round(labor_female$se,3), 
        rbind(round(labor_female$bws[1,1]),round(labor_female$bws[1,1]),round(labor_female$bws[1,1])), 
        rbind(labor_female$p,labor_female$p,labor_female$p), "Female",sum(labor_female$N), round(labor_female$ci,3)),
  cbind(round(labor_immig$coef,3), round(labor_immig$se,3), 
        rbind(round(labor_immig$bws[1,1]),round(labor_immig$bws[1,1]),round(labor_immig$bws[1,1])), 
        rbind(labor_immig$p,labor_immig$p,labor_immig$p), "Immigrant",sum(labor_immig$N), round(labor_immig$ci,3)),
  cbind(round(undecided$coef,3), round(undecided$se,3), 
        rbind(round(undecided$bws[1,1]),round(undecided$bws[1,1]),round(undecided$bws[1,1])), 
        rbind(undecided$p,undecided$p,undecided$p), "Fulle",sum(undecided$N), round(undecided$ci,3)),
  cbind(round(undecided_male$coef,3), round(undecided_male$se,3), 
        rbind(round(undecided_male$bws[1,1]),round(undecided_male$bws[1,1]),round(undecided_male$bws[1,1])), 
        rbind(undecided_male$p,undecided_male$p,undecided_male$p), "Male", sum(undecided_male$N), round(undecided_male$ci,3)),
  cbind(round(undecided_female$coef,3), round(undecided_female$se,3), 
        rbind(round(undecided_female$bws[1,1]),round(undecided_female$bws[1,1]),round(undecided_female$bws[1,1])), 
        rbind(undecided_female$p,undecided_female$p,undecided_female$p), "Female",sum(undecided_female$N), round(undecided_female$ci,3)),
  cbind(round(undecided_immig$coef,3), round(undecided_immig$se,3), 
        rbind(round(undecided_immig$bws[1,1]),round(undecided_immig$bws[1,1]),round(undecided_immig$bws[1,1])), 
        rbind(undecided_immig$p,undecided_immig$p,undecided_immig$p), "Immigrant",sum(undecided_immig$N), round(undecided_immig$ci,3)))

main_result_mf_df <- as.data.frame(main_result_mf) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Sample" = "V5",
                  "Obs." = "V6") %>% 
  slice(6,9,12,18,21,24) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust.1" ~ "Labor",
           rowname == "Robust.2" ~ "Labor ",
           rowname == "Robust.3" ~ " Labor",
           rowname == "Robust.5" ~ "Undecided",
           rowname == "Robust.6" ~ "Undecided ",
           rowname == "Robust.7" ~ " Undecided"),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

main_result_mf_df<- rotate_df(main_result_mf_df, cn =T)

main_result_mf_df[2,] <- paste0("(", format(unlist(main_result_mf_df[2,])),")")  
rownames(main_result_mf_df)[rownames(main_result_mf_df) == "Estimate"] <- ""
rownames(main_result_mf_df)[rownames(main_result_mf_df) == "SE"] <- " "

stargazer(main_result_mf_df,
          summary = FALSE, rownames = T,
          title = "RD Estimates -- The Effects of Conscription Eligibility in 1973 by Subgroups",
          multicolumn = T,
          label = "tab:rd_mf",
          column.sep.width = "5pt",
          font.size = "small",
          style = "ajps",
          header=FALSE, 
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal bandwidths and a triangular kernal,", 
                    "Robust standard errors in parentheses."),
          notes.append = F,
          notes.align = "l")



#Table A5------

labor_below54 <- rdrobust(ines_master$vote_labor[ines_master$age_in_73<54], 
                          ines_master$age_in_73[ines_master$age_in_73<54],
                          c = 18, p = 1)
summary(labor_below54)


likud_below54 <- rdrobust(ines_master$vote_likud[ines_master$age_in_73<54], 
                          ines_master$age_in_73[ines_master$age_in_73<54],
                          c = 18, p = 1)
summary(likud_below54)


undecided_below54 <- rdrobust(ines_master$undecide[ines_master$age_in_73<54], 
                              ines_master$age_in_73[ines_master$age_in_73<54],
                              c = 18, p = 1)
summary(undecided_below54)


turnout_below54 <- rdrobust(ines_master$no_vote[ines_master$age_in_73<54], 
                            ines_master$age_in_73[ines_master$age_in_73<54],
                            c = 18, p = 1)
summary(turnout_below54)


# Create Data frame for Table
main_result_below54 <- rbind(
  cbind(round(labor_below54$coef,3), round(labor_below54$se,3), 
        rbind(round(labor_below54$bws[1,1]),round(labor_below54$bws[1,1]),round(labor_below54$bws[1,1])), 
        rbind(labor_below54$p,labor_below54$p,labor_below54$p), sum(labor_below54$N), round(labor_below54$ci,3)),
  cbind(round(likud_below54$coef,3), round(likud_below54$se,3), 
        rbind(round(likud_below54$bws[1,1]),round(likud_below54$bws[1,1]),round(likud_below54$bws[1,1])), 
        rbind(likud_below54$p,likud_below54$p,likud_below54$p), sum(likud_below54$N), round(likud_below54$ci,3)),
  cbind(round(undecided_below54$coef,3), round(undecided_below54$se,3), 
        rbind(round(undecided_below54$bws[1,1]),round(undecided_below54$bws[1,1]),round(undecided_below54$bws[1,1])), 
        rbind(undecided_below54$p,undecided_below54$p,undecided_below54$p), sum(undecided_below54$N), round(undecided_below54$ci,3)),
  cbind(round(turnout_below54$coef,3), round(turnout_below54$se,3), 
        rbind(round(turnout_below54$bws[1,1]),round(turnout_below54$bws[1,1]),round(turnout_below54$bws[1,1])), 
        rbind(turnout_below54$p,turnout_below54$p,turnout_below54$p), sum(turnout_below54$N), round(turnout_below54$ci,3)))

main_result_below54_df <- as.data.frame(main_result_below54) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Obs." = "V5") %>% 
  slice(3,6,9,12) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "Labor",
           rowname == "Robust.1" ~ "Likud",
           rowname == "Robust.2" ~ "Undecided",
           rowname == "Robust.3" ~ "No Vote"
         ),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

main_result_below54_df<- rotate_df(main_result_below54_df, cn =T)

main_result_below54_df[2,] <- paste0("(", format(unlist(main_result_below54_df[2,])),")")  
rownames(main_result_below54_df)[rownames(main_result_below54_df) == "Estimate"] <- ""
rownames(main_result_below54_df)[rownames(main_result_below54_df) == "SE"] <- " "
stargazer(main_result_below54_df,
          summary = FALSE, rownames = T,
          title = "RD Estimates -- The Effects of Participation in 1973 War (Omiting Respondents 54+)",
          label = "tab:rd_below54",
          column.sep.width = "15pt",
          style = "ajps",
          font.size = "small",
          header=FALSE, 
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal, bandwidths",
                    "and a triangular kernal. Robust standard errors in parentheses."),
          notes.append = F,
          notes.align = "l")



#Table A6-----
labor2 <- rdrobust(ines_master$vote_labor, 
                   ines_master$age_in_73,
                   c = 18, p = 1)
summary(labor2)


likud2 <- rdrobust(ines_master$vote_likud, 
                   ines_master$age_in_73,
                   c = 18, p = 2)
summary(likud2)


undecided2 <- rdrobust(ines_master$undecide, 
                       ines_master$age_in_73,
                       c = 18, p = 2)
summary(undecided)


turnout2 <- rdrobust(ines_master$no_vote, 
                     ines_master$age_in_73,
                     c = 18, p = 2)
summary(turnout2)


# Create Data frame for Table
main_result2 <- rbind(
  cbind(round(labor2$coef,3), round(labor2$se,3), 
        rbind(round(labor2$bws[1,1]),round(labor2$bws[1,1]),round(labor2$bws[1,1])), 
        rbind(labor2$p,labor2$p,labor2$p), sum(labor2$N), round(labor2$ci,3)),
  cbind(round(likud2$coef,3), round(likud2$se,3), 
        rbind(round(likud2$bws[1,1]),round(likud2$bws[1,1]),round(likud2$bws[1,1])), 
        rbind(likud2$p,likud2$p,likud2$p), sum(likud2$N), round(likud2$ci,3)),
  cbind(round(undecided2$coef,3), round(undecided2$se,3), 
        rbind(round(undecided2$bws[1,1]),round(undecided2$bws[1,1]),round(undecided2$bws[1,1])), 
        rbind(undecided2$p,undecided2$p,undecided2$p), sum(undecided2$N), round(undecided2$ci,3)),
  cbind(round(turnout2$coef,3), round(turnout2$se,3), 
        rbind(round(turnout2$bws[1,1]),round(turnout2$bws[1,1]),round(turnout2$bws[1,1])), 
        rbind(turnout2$p,turnout2$p,turnout2$p), sum(turnout2$N), round(turnout2$ci,3)))

main_result_df2 <- as.data.frame(main_result2) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Obs." = "V5") %>% 
  slice(3,6,9,12) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "Labor",
           rowname == "Robust.1" ~ "Likud",
           rowname == "Robust.2" ~ "Undecided",
           rowname == "Robust.3" ~ "No Vote"
         ),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

main_result_df2<- rotate_df(main_result_df2, cn =T)

main_result_df2[2,] <- paste0("(", format(unlist(main_result_df2[2,])),")")  
rownames(main_result_df2)[rownames(main_result_df2) == "Estimate"] <- ""
rownames(main_result_df2)[rownames(main_result_df2) == "SE"] <- " "


stargazer(main_result_df2,
          summary = FALSE, rownames = T,
          title = "The Effects of Conscription Eligibility in 1973 -- (2nd Order Polynomial)",
          label = "tab:rd_pol2",
          column.sep.width = "15pt",
          style = "ajps",
          header=FALSE, 
          digit.separator	= ",",
          font.size = "small",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal bandwidths,",
                    "and a triangular kernal. Robust standard errors in parentheses."),
          notes.append = F,
          notes.align = "l")

# Table A7-------
labor_ep <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 18, p = 1, kernel = "epanechnikov")
summary(labor_ep)

labor_un <- rdrobust(ines_master$vote_labor, 
                     ines_master$age_in_73,
                     c = 18, p = 1, kernel = "uniform")
summary(labor_un)


likud_ep <- rdrobust(ines_master$vote_likud, 
                     ines_master$age_in_73,
                     c = 18, p = 1, kernel = "epanechnikov")
summary(likud_ep)

likud_un <- rdrobust(ines_master$vote_likud, 
                     ines_master$age_in_73,
                     c = 18, p = 1, kernel = "uniform")
summary(likud_un)


undecided_ep <- rdrobust(ines_master$undecide, 
                         ines_master$age_in_73,
                         c = 18, p = 1, kernel = "epanechnikov")
summary(undecided_ep)

undecided_un <- rdrobust(ines_master$undecide, 
                         ines_master$age_in_73,
                         c = 18, p = 1, kernel = "uniform")
summary(undecided_un)


turnout_ep <- rdrobust(ines_master$no_vote, 
                       ines_master$age_in_73,
                       c = 18, p = 2, kernel = "epanechnikov")
summary(turnout_ep)

turnout_un <- rdrobust(ines_master$no_vote, 
                       ines_master$age_in_73,
                       c = 18, p = 2, kernel = "uniform")
summary(turnout_un)


# Create Data frame for Table
main_result_kernel <- rbind(
  cbind(round(labor_ep$coef,3), round(labor_ep$se,3), 
        rbind(round(labor_ep$bws[1,1]),round(labor_ep$bws[1,1]),round(labor_ep$bws[1,1])), 
        rbind(labor_ep$p,labor_ep$p,labor_ep$p), labor_ep$kernel, sum(labor_ep$N), round(labor_ep$ci,3)),
  cbind(round(labor_un$coef,3), round(labor_un$se,3), 
        rbind(round(labor_un$bws[1,1]),round(labor_un$bws[1,1]),round(labor_un$bws[1,1])), 
        rbind(labor_un$p,labor_un$p,labor_un$p), labor_un$kernel, sum(labor_un$N), round(labor_un$ci,3)),
  cbind(round(likud_ep$coef,3), round(likud_ep$se,3), 
        rbind(round(likud_ep$bws[1,1]),round(likud_ep$bws[1,1]),round(likud_ep$bws[1,1])), 
        rbind(likud_ep$p,likud_ep$p,likud_ep$p), likud_ep$kernel, sum(likud_ep$N), round(likud_ep$ci,3)),
  cbind(round(likud_un$coef,3), round(likud_un$se,3), 
        rbind(round(likud_un$bws[1,1]),round(likud_un$bws[1,1]),round(likud_un$bws[1,1])), 
        rbind(likud_un$p,likud_un$p,likud_un$p), likud_un$kernel, sum(likud_un$N), round(likud_un$ci,3)),
  cbind(round(undecided_ep$coef,3), round(undecided_ep$se,3), 
        rbind(round(undecided_ep$bws[1,1]),round(undecided_ep$bws[1,1]),round(undecided_ep$bws[1,1])), 
        rbind(undecided_ep$p,undecided_ep$p,undecided_ep$p), undecided_ep$kernel, sum(undecided_ep$N), round(undecided_ep$ci,3)),
  cbind(round(undecided_un$coef,3), round(undecided_un$se,3), 
        rbind(round(undecided_un$bws[1,1]),round(undecided_un$bws[1,1]),round(undecided_un$bws[1,1])), 
        rbind(undecided_un$p,undecided_un$p,undecided_un$p), undecided_un$kernel, sum(undecided_un$N), round(undecided_un$ci,3)),
  cbind(round(turnout_ep$coef,3), round(turnout_ep$se,3), 
        rbind(round(turnout_ep$bws[1,1]),round(turnout_ep$bws[1,1]),round(turnout_ep$bws[1,1])), 
        rbind(turnout_ep$p,turnout_ep$p,turnout_ep$p), turnout_ep$kernel, sum(turnout_ep$N), round(turnout_ep$ci,3)),
  cbind(round(turnout_un$coef,3), round(turnout_un$se,3), 
        rbind(round(turnout_un$bws[1,1]),round(turnout_un$bws[1,1]),round(turnout_un$bws[1,1])), 
        rbind(turnout_un$p,turnout_un$p,turnout_un$p), turnout_un$kernel, sum(turnout_un$N), round(turnout_un$ci,3)))

main_result_kernel_df <- as.data.frame(main_result_kernel) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Kernel" = "V5",
                  "Obs." = "V6") %>% 
  slice(3,6,9,12,15,18,21,24) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "Labor",
           rowname == "Robust.1" ~ "Labor ",
           rowname == "Robust.2" ~ "Likud",
           rowname == "Robust.3" ~ "Likud ",
           rowname == "Robust.4" ~ "Undecided",
           rowname == "Robust.5" ~ "Undecided ",
           rowname == "Robust.6" ~ "No Vote",
           rowname == "Robust.7" ~ "No Vote "
         ),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

main_result_kernel_df<- rotate_df(main_result_kernel_df, cn =T)

main_result_kernel_df[2,] <- paste0("(", format(unlist(main_result_kernel_df[2,])),")")  
rownames(main_result_kernel_df)[rownames(main_result_kernel_df) == "Estimate"] <- ""
rownames(main_result_kernel_df)[rownames(main_result_kernel_df) == "SE"] <- " "


stargazer(main_result_kernel_df,
          summary = FALSE, rownames = T,
          title = "The Effects of Conscription Eligibility in 1973 -- (Alternative Kernel Functions)",
          label = "tab:rd_kernels",
          column.sep.width = "-5pt",
          font.size = "small",
          style = "ajps",
          header=FALSE, 
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal bandwidths. Robust standard errors in parentheses."),
          notes.append = F,
          notes.align = "l")

#Figure A5-------
labor_mserd <- rdrobust(ines_master$vote_labor, 
                        ines_master$age_in_73,
                        c = 18, p = 1)
summary(labor_mserd)


labor_msetwo <- rdrobust(ines_master$vote_labor, 
                         ines_master$age_in_73,
                         bwselect = "msetwo",
                         c = 18, p = 1)
summary(labor_msetwo)



labor_msesum <- rdrobust(ines_master$vote_labor, 
                         ines_master$age_in_73,
                         bwselect = "msesum",
                         c = 18, p = 1)
summary(labor_msesum)


labor_msecomb1 <- rdrobust(ines_master$vote_labor, 
                           ines_master$age_in_73,
                           bwselect = "msecomb1",
                           c = 18, p = 1)
summary(labor_msecomb1)


labor_msecomb2 <- rdrobust(ines_master$vote_labor, 
                           ines_master$age_in_73,
                           bwselect = "msecomb2",
                           c = 18, p = 1)
summary(labor_msecomb2)



labor_cerrd <- rdrobust(ines_master$vote_labor, 
                        ines_master$age_in_73,
                        bwselect = "cerrd",
                        c = 18, p = 1)
summary(labor_cerrd)


labor_certwo <- rdrobust(ines_master$vote_labor, 
                         ines_master$age_in_73,
                         bwselect = "certwo",
                         c = 18, p = 1)
summary(labor_certwo)



labor_cersum <- rdrobust(ines_master$vote_labor, 
                         ines_master$age_in_73,
                         bwselect = "cersum",
                         c = 18, p = 1)
summary(labor_cersum)



labor_cercomb1 <- rdrobust(ines_master$vote_labor, 
                           ines_master$age_in_73,
                           bwselect = "cercomb1",
                           c = 18, p = 1)
summary(labor_cercomb1)


labor_cercomb2 <- rdrobust(ines_master$vote_labor, 
                           ines_master$age_in_73,
                           bwselect = "cercomb2",
                           c = 18, p = 1)
summary(labor_cercomb2)




likud_mserd <- rdrobust(ines_master$vote_likud, 
                        ines_master$age_in_73,
                        c = 18, p = 1)
summary(likud_mserd)


likud_msetwo <- rdrobust(ines_master$vote_likud, 
                         ines_master$age_in_73,
                         bwselect = "msetwo",
                         c = 18, p = 1)
summary(likud_msetwo)



likud_msesum <- rdrobust(ines_master$vote_likud, 
                         ines_master$age_in_73,
                         bwselect = "msesum",
                         c = 18, p = 1)
summary(likud_msesum)


likud_msecomb1 <- rdrobust(ines_master$vote_likud, 
                           ines_master$age_in_73,
                           bwselect = "msecomb1",
                           c = 18, p = 1)
summary(likud_msecomb1)


likud_msecomb2 <- rdrobust(ines_master$vote_likud, 
                           ines_master$age_in_73,
                           bwselect = "msecomb2",
                           c = 18, p = 1)
summary(likud_msecomb2)



likud_cerrd <- rdrobust(ines_master$vote_likud, 
                        ines_master$age_in_73,
                        bwselect = "cerrd",
                        c = 18, p = 1)
summary(likud_cerrd)



likud_certwo <- rdrobust(ines_master$vote_likud, 
                         ines_master$age_in_73,
                         bwselect = "certwo",
                         c = 18, p = 1)
summary(likud_certwo)



likud_cersum <- rdrobust(ines_master$vote_likud, 
                         ines_master$age_in_73,
                         bwselect = "cersum",
                         c = 18, p = 1)
summary(likud_cersum)



likud_cercomb1 <- rdrobust(ines_master$vote_likud, 
                           ines_master$age_in_73,
                           bwselect = "cercomb1",
                           c = 18, p = 1)
summary(likud_cercomb1)


likud_cercomb2 <- rdrobust(ines_master$vote_likud, 
                           ines_master$age_in_73,
                           bwselect = "cercomb2",
                           c = 18, p = 1)
summary(likud_cercomb2)






undecide_mserd <- rdrobust(ines_master$undecide, 
                           ines_master$age_in_73,
                           c = 18, p = 1)
summary(undecide_mserd)


undecide_msetwo <- rdrobust(ines_master$undecide, 
                            ines_master$age_in_73,
                            bwselect = "msetwo",
                            c = 18, p = 1)
summary(undecide_msetwo)



undecide_msesum <- rdrobust(ines_master$undecide, 
                            ines_master$age_in_73,
                            bwselect = "msesum",
                            c = 18, p = 1)
summary(undecide_msesum)


undecide_msecomb1 <- rdrobust(ines_master$undecide, 
                              ines_master$age_in_73,
                              bwselect = "msecomb1",
                              c = 18, p = 1)
summary(undecide_msecomb1)


undecide_msecomb2 <- rdrobust(ines_master$undecide, 
                              ines_master$age_in_73,
                              bwselect = "msecomb2",
                              c = 18, p = 1)
summary(undecide_msecomb2)



undecide_cerrd <- rdrobust(ines_master$undecide, 
                           ines_master$age_in_73,
                           bwselect = "cerrd",
                           c = 18, p = 1)
summary(undecide_cerrd)



undecide_certwo <- rdrobust(ines_master$undecide, 
                            ines_master$age_in_73,
                            bwselect = "certwo",
                            c = 18, p = 1)
summary(undecide_certwo)



undecide_cersum <- rdrobust(ines_master$undecide, 
                            ines_master$age_in_73,
                            bwselect = "cersum",
                            c = 18, p = 1)
summary(undecide_cersum)



undecide_cercomb1 <- rdrobust(ines_master$undecide, 
                              ines_master$age_in_73,
                              bwselect = "cercomb1",
                              c = 18, p = 1)
summary(undecide_cercomb1)


undecide_cercomb2 <- rdrobust(ines_master$undecide, 
                              ines_master$age_in_73,
                              bwselect = "cercomb2",
                              c = 18, p = 1)
summary(undecide_cercomb2)




turnout_mserd <- rdrobust(ines_master$no_vote, 
                          ines_master$age_in_73,
                          c = 18, p = 1)
summary(turnout_mserd)


turnout_msetwo <- rdrobust(ines_master$no_vote, 
                           ines_master$age_in_73,
                           bwselect = "msetwo",
                           c = 18, p = 1)
summary(turnout_msetwo)



turnout_msesum <- rdrobust(ines_master$no_vote, 
                           ines_master$age_in_73,
                           bwselect = "msesum",
                           c = 18, p = 1)
summary(turnout_msesum)


turnout_msecomb1 <- rdrobust(ines_master$no_vote, 
                             ines_master$age_in_73,
                             bwselect = "msecomb1",
                             c = 18, p = 1)
summary(turnout_msecomb1)


turnout_msecomb2 <- rdrobust(ines_master$no_vote, 
                             ines_master$age_in_73,
                             bwselect = "msecomb2",
                             c = 18, p = 1)
summary(turnout_msecomb2)



turnout_cerrd <- rdrobust(ines_master$no_vote, 
                          ines_master$age_in_73,
                          bwselect = "cerrd",
                          c = 18, p = 1)
summary(turnout_cerrd)



turnout_certwo <- rdrobust(ines_master$no_vote, 
                           ines_master$age_in_73,
                           bwselect = "certwo",
                           c = 18, p = 1)
summary(turnout_certwo)



turnout_cersum <- rdrobust(ines_master$no_vote, 
                           ines_master$age_in_73,
                           bwselect = "cersum",
                           c = 18, p = 1)
summary(turnout_cersum)



turnout_cercomb1 <- rdrobust(ines_master$no_vote, 
                             ines_master$age_in_73,
                             bwselect = "cercomb1",
                             c = 18, p = 1)
summary(turnout_cercomb1)


turnout_cercomb2 <- rdrobust(ines_master$no_vote, 
                             ines_master$age_in_73,
                             bwselect = "cercomb2",
                             c = 18, p = 1)
summary(turnout_cercomb2)



## Plot Difference Bandwith Selections


# Create Placebo dataframe

bw_select <- rbind(cbind(labor_mserd$coef, labor_mserd$ci, labor_mserd$bwselect, "Labor"),
                   cbind(labor_msetwo$coef, labor_msetwo$ci, labor_msetwo$bwselect, "Labor"),
                   cbind(labor_msesum$coef, labor_msesum$ci, labor_msesum$bwselect, "Labor"),
                   cbind(labor_msecomb1$coef, labor_msecomb1$ci, labor_msecomb1$bwselect, "Labor"),
                   cbind(labor_msecomb1$coef, labor_msecomb1$ci, labor_msecomb1$bwselect, "Labor"),
                   cbind(labor_msecomb2$coef, labor_msecomb2$ci, labor_msecomb2$bwselect, "Labor"),
                   cbind(labor_cerrd$coef, labor_cerrd$ci, labor_cerrd$bwselect, "Labor"),
                   cbind(labor_certwo$coef, labor_certwo$ci, labor_certwo$bwselect, "Labor"),
                   cbind(labor_cersum$coef, labor_cersum$ci, labor_cersum$bwselect, "Labor"),
                   cbind(labor_cercomb1$coef, labor_cercomb1$ci, labor_cercomb1$bwselect, "Labor"),
                   cbind(labor_cercomb2$coef, labor_cercomb2$ci, labor_cercomb2$bwselect, "Labor"),
                   cbind(likud_mserd$coef, likud_mserd$ci, likud_mserd$bwselect, "Likud"),
                   cbind(likud_msetwo$coef, likud_msetwo$ci, likud_msetwo$bwselect, "Likud"),
                   cbind(likud_msesum$coef, likud_msesum$ci, likud_msesum$bwselect, "Likud"),
                   cbind(likud_msecomb1$coef, likud_msecomb1$ci, likud_msecomb1$bwselect, "Likud"),
                   cbind(likud_msecomb1$coef, likud_msecomb1$ci, likud_msecomb1$bwselect, "Likud"),
                   cbind(likud_msecomb2$coef, likud_msecomb2$ci, likud_msecomb2$bwselect, "Likud"),
                   cbind(likud_cerrd$coef, likud_cerrd$ci, likud_cerrd$bwselect, "Likud"),
                   cbind(likud_certwo$coef, likud_certwo$ci, likud_certwo$bwselect, "Likud"),
                   cbind(likud_cersum$coef, likud_cersum$ci, likud_cersum$bwselect, "Likud"),
                   cbind(likud_cercomb1$coef, likud_cercomb1$ci, likud_cercomb1$bwselect, "Likud"),
                   cbind(likud_cercomb2$coef, likud_cercomb2$ci, likud_cercomb2$bwselect, "Likud"),
                   cbind(undecide_mserd$coef, undecide_mserd$ci, undecide_mserd$bwselect, "Undecided"),
                   cbind(undecide_msetwo$coef, undecide_msetwo$ci, undecide_msetwo$bwselect, "Undecided"),
                   cbind(undecide_msesum$coef, undecide_msesum$ci, undecide_msesum$bwselect, "Undecided"),
                   cbind(undecide_msecomb1$coef, undecide_msecomb1$ci, undecide_msecomb1$bwselect, "Undecided"),
                   cbind(undecide_msecomb1$coef, undecide_msecomb1$ci, undecide_msecomb1$bwselect, "Undecided"),
                   cbind(undecide_msecomb2$coef, undecide_msecomb2$ci, undecide_msecomb2$bwselect, "Undecided"),
                   cbind(undecide_cerrd$coef, undecide_cerrd$ci, undecide_cerrd$bwselect, "Undecided"),
                   cbind(undecide_certwo$coef, undecide_certwo$ci, undecide_certwo$bwselect, "Undecided"),
                   cbind(undecide_cersum$coef, undecide_cersum$ci, undecide_cersum$bwselect, "Undecided"),
                   cbind(undecide_cercomb1$coef, undecide_cercomb1$ci, undecide_cercomb1$bwselect, "Undecided"),
                   cbind(undecide_cercomb2$coef, undecide_cercomb2$ci, undecide_cercomb2$bwselect, "Undecided"),
                   cbind(turnout_mserd$coef, turnout_mserd$ci, turnout_mserd$bwselect, "No Vote"),
                   cbind(turnout_msetwo$coef, turnout_msetwo$ci, turnout_msetwo$bwselect, "No Vote"),
                   cbind(turnout_msesum$coef, turnout_msesum$ci, turnout_msesum$bwselect, "No Vote"),
                   cbind(turnout_msecomb1$coef, turnout_msecomb1$ci, turnout_msecomb1$bwselect, "No Vote"),
                   cbind(turnout_msecomb1$coef, turnout_msecomb1$ci, turnout_msecomb1$bwselect, "No Vote"),
                   cbind(turnout_msecomb2$coef, turnout_msecomb2$ci, turnout_msecomb2$bwselect, "No Vote"),
                   cbind(turnout_cerrd$coef, turnout_cerrd$ci, turnout_cerrd$bwselect, "No Vote"),
                   cbind(turnout_certwo$coef, turnout_certwo$ci, turnout_certwo$bwselect, "No Vote"),
                   cbind(turnout_cersum$coef, turnout_cersum$ci, turnout_cersum$bwselect, "No Vote"),
                   cbind(turnout_cercomb1$coef, turnout_cercomb1$ci, turnout_cercomb1$bwselect, "No Vote"),
                   cbind(turnout_cercomb2$coef, turnout_cercomb2$ci, turnout_cercomb2$bwselect, "No Vote")) 
bw_select <- as.data.frame(bw_select) %>% 
  slice(seq(3,300,3)) %>% 
  rename(.,
         low = "CI Lower",
         high = "CI Upper") %>% 
  mutate(.,
         low = as.numeric(low),
         high = as.numeric(high))


bw_select$V4 <-
  factor(bw_select$V4, 
         c("mserd","msetwo","msesum", "msecomb1","msecomb2",
           "cercomb1", "cercomb2","cerrd","certwo", "cersum"))
# Plot Placebo

ggplot(bw_select, aes(x = as.factor(V5), y = as.numeric(Coeff), colour = as.factor(V4))) +
  geom_hline(yintercept = 0, color = "gray50", linetype = 2, size = 0.2) +
  geom_pointrange(aes(ymin = low, ymax = high),
                  position = position_dodge(width = 0.6)) +
  labs(x = "Outcome",
       y = "LATE", 
       color = "Bandwith \nSelection \nMethod") +
  guides(color = guide_legend(reverse = F))+
  theme(panel.grid.major = element_blank(), 
        axis.text.x = element_text(size = 12),
        plot.caption = element_text(size = 10, family = "Times",hjust = -.02),
        legend.position = "bottom",
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        legend.key=element_blank(),
        axis.line = element_line(colour = "black"))

#Table A8----------

# Crete indicaotor for years with multiple waves
ines_master <- ines_master %>% 
  mutate(.,
         mult_surv_81 = case_when(
           election_year == 1981 ~ 1,
           election_year == "1981.1" ~ 1,
           election_year == "1981.2" ~ 1),
         mult_surv_88 = case_when(
           election_year == 1988 ~ 1,
           election_year == "1988.1" ~ 1),
         mult_surv_81 = ifelse(is.na(mult_surv_81), 0,1),
         mult_surv_88 = ifelse(is.na(mult_surv_88), 0,1))

# Run models

labor_no77 <- rdrobust(ines_master$vote_labor[ines_master$election_year >1977], 
                       ines_master$age_in_73[ines_master$election_year  >1977],
                       c = 18, p = 1)
summary(labor_no77)

labor_no81 <- rdrobust(ines_master$vote_labor[ines_master$mult_surv_81!=1], 
                       ines_master$age_in_73[ines_master$mult_surv_81!=1],
                       c = 18, p = 1)
summary(labor_no81)

labor_no84 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 1984], 
                       ines_master$age_in_73[ines_master$election_year != 1984],
                       c = 18, p = 1)
summary(labor_no84)


labor_no88 <- rdrobust(ines_master$vote_labor[ines_master$mult_surv_88 != 1], 
                       ines_master$age_in_73[ines_master$mult_surv_88 != 1],
                       c = 18, p = 1)
summary(labor_no88)

labor_no92 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 1992], 
                       ines_master$age_in_73[ines_master$election_year != 1992], 
                       c = 18, p = 1)
summary(labor_no92)

labor_no96 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 1996], 
                       ines_master$age_in_73[ines_master$election_year != 1996], 
                       c = 18, p = 1)
summary(labor_no96)


labor_no99 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 1999], 
                       ines_master$age_in_73[ines_master$election_year != 1999], 
                       c = 18, p = 1)
summary(labor_no99)

labor_no01 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2001], 
                       ines_master$age_in_73[ines_master$election_year != 2001], 
                       c = 18, p = 1)
summary(labor_no01)


labor_no03 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2003], 
                       ines_master$age_in_73[ines_master$election_year != 2003], 
                       c = 18, p = 1)
summary(labor_no03)


labor_no06 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2006], 
                       ines_master$age_in_73[ines_master$election_year != 2006], 
                       c = 18, p = 1)
summary(labor_no06)

labor_no09 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2009], 
                       ines_master$age_in_73[ines_master$election_year != 2009], 
                       c = 18, p = 1)
summary(labor_no09)

labor_no13 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2013], 
                       ines_master$age_in_73[ines_master$election_year != 2013], 
                       c = 18, p = 1)
summary(labor_no13)

labor_no15 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2015], 
                       ines_master$age_in_73[ines_master$election_year != 2015], 
                       c = 18, p = 1)
summary(labor_no15)


labor_no19 <- rdrobust(ines_master$vote_labor[ines_master$election_year != 2019], 
                       ines_master$age_in_73[ines_master$election_year != 2019], 
                       c = 18, p = 1)
summary(labor_no19)


# Create Data frame for Table
omit_years <- rbind(
  cbind(round(labor_no77$coef,3), round(labor_no77$se,3), 
        rbind(round(labor_no77$bws[1,1]),round(labor_no77$bws[1,1]),round(labor_no77$bws[1,1])), 
        rbind(labor_no77$p,labor_no77$p,labor_no77$p), sum(labor_no77$N), round(labor_no77$ci,3)),
  cbind(round(labor_no81$coef,3), round(labor_no81$se,3), 
        rbind(round(labor_no81$bws[1,1]),round(labor_no81$bws[1,1]),round(labor_no81$bws[1,1])), 
        rbind(labor_no81$p,labor_no81$p,labor_no81$p), sum(labor_no81$N), round(labor_no81$ci,3)),
  cbind(round(labor_no84$coef,3), round(labor_no84$se,3), 
        rbind(round(labor_no84$bws[1,1]),round(labor_no84$bws[1,1]),round(labor_no84$bws[1,1])), 
        rbind(labor_no84$p,labor_no84$p,labor_no84$p), sum(labor_no84$N), round(labor_no84$ci,3)),
  cbind(round(labor_no88$coef,3), round(labor_no88$se,3), 
        rbind(round(labor_no88$bws[1,1]),round(labor_no88$bws[1,1]),round(labor_no88$bws[1,1])), 
        rbind(labor_no88$p,labor_no88$p,labor_no88$p), sum(labor_no88$N), round(labor_no88$ci,3)),
  cbind(round(labor_no92$coef,3), round(labor_no92$se,3), 
        rbind(round(labor_no92$bws[1,1]),round(labor_no92$bws[1,1]),round(labor_no92$bws[1,1])), 
        rbind(labor_no92$p,labor_no92$p,labor_no92$p), sum(labor_no92$N), round(labor_no92$ci,3)),
  cbind(round(labor_no96$coef,3), round(labor_no96$se,3), 
        rbind(round(labor_no96$bws[1,1]),round(labor_no96$bws[1,1]),round(labor_no96$bws[1,1])), 
        rbind(labor_no96$p,labor_no96$p,labor_no96$p), sum(labor_no96$N), round(labor_no96$ci,3)),
  cbind(round(labor_no99$coef,3), round(labor_no99$se,3), 
        rbind(round(labor_no99$bws[1,1]),round(labor_no99$bws[1,1]),round(labor_no99$bws[1,1])), 
        rbind(labor_no99$p,labor_no99$p,labor_no99$p), sum(labor_no99$N), round(labor_no99$ci,3)),
  cbind(round(labor_no01$coef,3), round(labor_no01$se,3), 
        rbind(round(labor_no01$bws[1,1]),round(labor_no01$bws[1,1]),round(labor_no01$bws[1,1])), 
        rbind(labor_no01$p,labor_no01$p,labor_no01$p), sum(labor_no01$N), round(labor_no01$ci,3)),
  cbind(round(labor_no03$coef,3), round(labor_no03$se,3), 
        rbind(round(labor_no03$bws[1,1]),round(labor_no03$bws[1,1]),round(labor_no03$bws[1,1])), 
        rbind(labor_no03$p,labor_no03$p,labor_no03$p), sum(labor_no03$N), round(labor_no03$ci,3)),
  cbind(round(labor_no06$coef,3), round(labor_no06$se,3), 
        rbind(round(labor_no06$bws[1,1]),round(labor_no06$bws[1,1]),round(labor_no06$bws[1,1])), 
        rbind(labor_no06$p,labor_no06$p,labor_no06$p), sum(labor_no06$N), round(labor_no06$ci,3)),
  cbind(round(labor_no09$coef,3), round(labor_no09$se,3), 
        rbind(round(labor_no09$bws[1,1]),round(labor_no09$bws[1,1]),round(labor_no09$bws[1,1])), 
        rbind(labor_no09$p,labor_no09$p,labor_no09$p), sum(labor_no09$N), round(labor_no09$ci,3)),
  cbind(round(labor_no13$coef,3), round(labor_no13$se,3), 
        rbind(round(labor_no13$bws[1,1]),round(labor_no13$bws[1,1]),round(labor_no13$bws[1,1])), 
        rbind(labor_no13$p,labor_no13$p,labor_no13$p), sum(labor_no13$N), round(labor_no13$ci,3)),
  cbind(round(labor_no15$coef,3), round(labor_no15$se,3), 
        rbind(round(labor_no15$bws[1,1]),round(labor_no15$bws[1,1]),round(labor_no15$bws[1,1])), 
        rbind(labor_no15$p,labor_no15$p,labor_no15$p), sum(labor_no15$N), round(labor_no15$ci,3)),
  cbind(round(labor_no19$coef,3), round(labor_no19$se,3), 
        rbind(round(labor_no19$bws[1,1]),round(labor_no19$bws[1,1]),round(labor_no19$bws[1,1])), 
        rbind(labor_no19$p,labor_no19$p,labor_no19$p), sum(labor_no19$N), round(labor_no19$ci,3)))

omit_years_df <- as.data.frame(omit_years) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Obs." = "V5") %>% 
  slice(3,6,9,12,15,18,21,24,27,30,33,36,39,42) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "77",
           rowname == "Robust.1" ~ "81",
           rowname == "Robust.2" ~ "84",
           rowname == "Robust.3" ~ "88",
           rowname == "Robust.4" ~ "92",
           rowname == "Robust.5" ~ "96",
           rowname == "Robust.6" ~ "99",
           rowname == "Robust.7" ~ "01",
           rowname == "Robust.8" ~ "03",
           rowname == "Robust.9" ~ "06",
           rowname == "Robust.10" ~ "09",
           rowname == "Robust.11" ~ "13",
           rowname == "Robust.12" ~ "15",
           rowname == "Robust.13" ~ "19"),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

omit_years_df<- rotate_df(omit_years_df, cn =T)

omit_years_df[2,] <- paste0("(", format(unlist(omit_years_df[2,])),")")  
rownames(omit_years_df)[rownames(omit_years_df) == "Estimate"] <- ""
rownames(omit_years_df)[rownames(omit_years_df) == "SE"] <- " "
stargazer(omit_years_df,
          summary = FALSE, rownames = T,
          title = "RD Estimates -- Omit One Year from Sample",
          label = "tab:omit_years",
          column.sep.width = "-10pt", 
          # column.sep.width = "0.5",
          style = "ajps",
          font.size = "small",
          header=FALSE, 
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal bandwidths, and a triangular kernal. Robust standard errors",
                    "in parentheses. Each column omits survey respondents from one INES wave."),
          notes.append = F,
          notes.align = "l")

#Table A9----------
# Create FE matrix
fe <- ines_master %>% 
  select(election_year) 
fe <- fastDummies::dummy_cols(fe)
summary(fe)

labor_fese <- rdrobust(ines_master$undecide, 
                       ines_master$age_in_73,
                       covs = fe,
                       cluster = ines_master$election_year,
                       c = 18, p = 1) 
summary(labor_fese)


likud_fese <- rdrobust(ines_master$vote_likud, 
                       ines_master$age_in_73,
                       covs = fe,
                       cluster = ines_master$election_year,
                       c = 18, p = 1)
summary(likud_fese)


undecided_fese <- rdrobust(ines_master$undecide, 
                           ines_master$age_in_73,
                           covs = fe,
                           cluster = ines_master$election_year,
                           c = 18, p = 1)
summary(undecided_fese)


turnout_fese <- rdrobust(ines_master$no_vote, 
                         ines_master$age_in_73,
                         covs = fe,
                         cluster = ines_master$election_year,
                         c = 18, p = 1)
summary(turnout_fese)


# Create Data frame for Table
main_result_fese <- rbind(
  cbind(round(labor_fese$coef,3), round(labor_fese$se,3), 
        rbind(round(labor_fese$bws[1,1]),round(labor_fese$bws[1,1]),round(labor_fese$bws[1,1])), 
        rbind(labor_fese$p,labor_fese$p,labor_fese$p), "Cycle", "Cycle", sum(labor_fese$N), round(labor_fese$ci,3)),
  cbind(round(likud_fese$coef,3), round(likud_fese$se,3), 
        rbind(round(likud_fese$bws[1,1]),round(likud_fese$bws[1,1]),round(likud_fese$bws[1,1])), 
        rbind(likud_fese$p,likud_fese$p,likud_fese$p), "Cycle", "Cycle", sum(likud_fese$N), round(likud_fese$ci,3)),
  cbind(round(undecided_fese$coef,3), round(undecided_fese$se,3), 
        rbind(round(undecided_fese$bws[1,1]),round(undecided_fese$bws[1,1]),round(undecided_fese$bws[1,1])), 
        rbind(undecided_fese$p,undecided_fese$p,undecided_fese$p), "Cycle", "Cycle", sum(undecided_fese$N), round(undecided_fese$ci,3)),
  cbind(round(turnout_fese$coef,3), round(turnout_fese$se,3), 
        rbind(round(turnout_fese$bws[1,1]),round(turnout_fese$bws[1,1]),round(turnout_fese$bws[1,1])), 
        rbind(turnout_fese$p,turnout_fese$p,turnout_fese$p), "Cycle", "Cycle", sum(turnout_fese$N), round(turnout_fese$ci,3)))

main_result_fese_df <- as.data.frame(main_result_fese) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Fixed-Effect" = "V5",
                  "Cluster" = "V6",
                  "Obs." = "V7") %>% 
  slice(3,6,9,12) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "Labor",
           rowname == "Robust.1" ~ "Likud",
           rowname == "Robust.2" ~ "Undecided",
           rowname == "Robust.3" ~ "No Vote"
         ),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

main_result_fese_df<- rotate_df(main_result_fese_df, cn =T)

main_result_fese_df[2,] <- paste0("(", format(unlist(main_result_fese_df[2,])),")")  
rownames(main_result_fese_df)[rownames(main_result_fese_df) == "Estimate"] <- ""
rownames(main_result_fese_df)[rownames(main_result_fese_df) == "SE"] <- " "
stargazer(main_result_fese_df,
          summary = FALSE, rownames = T,
          title = "RD Estimates -- The Effects of Participation in 1973 War (Accounting for Cycle)",
          label = "tab:rd_fese",
          column.sep.width = "15pt",
          style = "ajps",
          font.size = "small",
          header=FALSE, 
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal, bandwidths",
                    "and a triangular kernal. Models include cycle fixed-effects,", 
                    "and robust standard errors clustered by cycle in parentheses."),
          notes.append = F,
          notes.align = "l")



#Table A10------

# create control DF
controls <- ines_master %>% 
  mutate(.,
         male = ifelse(Sex == "male",1,0),
         academic = ifelse(edu == "Academic",1,0),
         hs = ifelse(edu == "HS",1,0),
         religious = ifelse(relig == "Relig",1,0),
         secular = ifelse(relig == "Secular",1,0),
         traditional = ifelse(relig == "Traditional",1,0)) %>% 
  select(.,
         ashkenazi, male:traditional)
controls <- data.frame(controls)

# Estimate models with controls
labor_covs <- rdrobust(ines_master$vote_labor, 
                       ines_master$age_in_73,
                       covs = controls,
                       c = 18, p = 1)
summary(labor_covs)


likud_covs <- rdrobust(ines_master$vote_likud, 
                       ines_master$age_in_73,
                       covs = controls,
                       c = 18, p = 1)
summary(likud_covs)


undecided_covs <- rdrobust(ines_master$undecide, 
                           ines_master$age_in_73,
                           covs = controls,
                           c = 18, p = 1)
summary(undecided_covs)


turnout_covs <- rdrobust(ines_master$no_vote, 
                         ines_master$age_in_73,
                         covs = controls,
                         c = 18, p = 1)
summary(turnout_covs)


# Create Data frame for Table
main_result_covs <- rbind(
  cbind(round(labor_covs$coef,3), round(labor_covs$se,3), 
        rbind(round(labor_covs$bws[1,1]),round(labor_covs$bws[1,1]),round(labor_covs$bws[1,1])), 
        rbind(labor_covs$p,labor_covs$p,labor_covs$p), sum(labor_covs$N), round(labor_covs$ci,3)),
  cbind(round(likud_covs$coef,3), round(likud_covs$se,3), 
        rbind(round(likud_covs$bws[1,1]),round(likud_covs$bws[1,1]),round(likud_covs$bws[1,1])), 
        rbind(likud_covs$p,likud_covs$p,likud_covs$p), sum(likud_covs$N), round(likud_covs$ci,3)),
  cbind(round(undecided_covs$coef,3), round(undecided_covs$se,3), 
        rbind(round(undecided_covs$bws[1,1]),round(undecided_covs$bws[1,1]),round(undecided_covs$bws[1,1])), 
        rbind(undecided_covs$p,undecided_covs$p,undecided_covs$p), sum(undecided_covs$N), round(undecided_covs$ci,3)),
  cbind(round(turnout_covs$coef,3), round(turnout_covs$se,3), 
        rbind(round(turnout_covs$bws[1,1]),round(turnout_covs$bws[1,1]),round(turnout_covs$bws[1,1])), 
        rbind(turnout_covs$p,turnout_covs$p,turnout_covs$p), sum(turnout_covs$N), round(turnout_covs$ci,3)))

main_result_covs_df <- as.data.frame(main_result_covs) %>% 
  dplyr :: rename(.,
                  "Estimate" = "Coeff",
                  "SE" = "Std. Err.",
                  "Bandwidth" = "V3",
                  "Poly" = "V4",
                  "Obs." = "V5") %>% 
  slice(3,6,9,12) %>% 
  rownames_to_column() %>% 
  mutate(.,
         rowname = case_when(
           rowname == "Robust" ~ "Labor",
           rowname == "Robust.1" ~ "Likud",
           rowname == "Robust.2" ~ "Undecided",
           rowname == "Robust.3" ~ "No Vote"
         ),
         rename(.,
                Outcome = rowname)) %>% 
  select(.,
         -Poly, -"CI Lower", -"CI Upper", -Outcome)

main_result_covs_df<- rotate_df(main_result_covs_df, cn =T)

main_result_covs_df[2,] <- paste0("(", format(unlist(main_result_covs_df[2,])),")")  
rownames(main_result_covs_df)[rownames(main_result_covs_df) == "Estimate"] <- ""
rownames(main_result_covs_df)[rownames(main_result_covs_df) == "SE"] <- " "
stargazer(main_result_covs_df,
          summary = FALSE, rownames = T,
          title = "RD Estimates -- The Effects of Participation in 1973 War (with Controls)",
          label = "tab:rd_controls",
          column.sep.width = "15pt",
          style = "ajps",
          font.size = "small",
          header=FALSE, 
          digit.separator	= ",",
          digits = 3,
          notes = c("Regression discontinuity models with MSE optimal, bandwidths",
                    "and a triangular kernal. Robust standard errors in parentheses.",
                    "Controls include gender, religiosity, ethnicity, and education."),
          notes.append = F,
          notes.align = "l")

#Figure A6-----
labor_all <- rdrobust(ines_master$vote_labor, 
                      ines_master$age_in_73,
                      c = 18, p = 1)
summary(labor_all)

labor_pre2019 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2019], 
                          ines_master$age_in_73[ines_master$election_year<2019],
                          c = 18, p = 1)
summary(labor_pre2019)

labor_pre2015 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2015], 
                          ines_master$age_in_73[ines_master$election_year<2015],
                          c = 18, p = 1)
summary(labor_pre2015)

labor_pre2013 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2013], 
                          ines_master$age_in_73[ines_master$election_year<2013],
                          c = 18, p = 1)
summary(labor_pre2013)

labor_pre2009 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2009], 
                          ines_master$age_in_73[ines_master$election_year<2009],
                          c = 18, p = 1)
summary(labor_pre2009)

labor_pre2006 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2006], 
                          ines_master$age_in_73[ines_master$election_year<2006],
                          c = 18, p = 1)
summary(labor_pre2006)


labor_pre2003 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2003], 
                          ines_master$age_in_73[ines_master$election_year<2003],
                          c = 18, p = 1)
summary(labor_pre2003)

labor_pre2001 <- rdrobust(ines_master$vote_labor[ines_master$election_year<2001], 
                          ines_master$age_in_73[ines_master$election_year<2001],
                          c = 18, p = 1)
summary(labor_pre2001)

labor_pre1999 <- rdrobust(ines_master$vote_labor[ines_master$election_year<1999], 
                          ines_master$age_in_73[ines_master$election_year<1999],
                          c = 18, p = 1)
summary(labor_pre1999)


labor_pre1996 <- rdrobust(ines_master$vote_labor[ines_master$election_year<1996], 
                          ines_master$age_in_73[ines_master$election_year<1996],
                          c = 18, p = 1)
summary(labor_pre1996)

labor_pre1992 <- rdrobust(ines_master$vote_labor[ines_master$election_year<1992], 
                          ines_master$age_in_73[ines_master$election_year<1992],
                          c = 18, p = 1)
summary(labor_pre1992)




long_term <- rbind(cbind(labor_all$coef, labor_all$ci, sum(labor_all$N), "1977-2019", labor_all$pv),
                   cbind(labor_pre2019$coef, labor_pre2019$ci, sum(labor_pre2019$N), "1977-2015", labor_pre2019$pv),
                   cbind(labor_pre2015$coef, labor_pre2015$ci, sum(labor_pre2015$N), "1977-2013", labor_pre2015$pv),
                   cbind(labor_pre2013$coef, labor_pre2013$ci, sum(labor_pre2013$N), "1977-2009", labor_pre2013$pv),
                   cbind(labor_pre2009$coef, labor_pre2009$ci, sum(labor_pre2009$N), "1977-2006", labor_pre2009$pv),
                   cbind(labor_pre2006$coef, labor_pre2006$ci, sum(labor_pre2006$N), "1977-2003", labor_pre2006$pv),
                   cbind(labor_pre2003$coef, labor_pre2003$ci, sum(labor_pre2003$N), "1977-2001", labor_pre2003$pv),
                   cbind(labor_pre2001$coef, labor_pre2001$ci, sum(labor_pre2001$N), "1977-1999", labor_pre2001$pv),
                   cbind(labor_pre1999$coef, labor_pre1999$ci, sum(labor_pre1999$N), "1977-1996", labor_pre1999$pv),
                   cbind(labor_pre1996$coef, labor_pre1996$ci, sum(labor_pre1996$N), "1977-1992", labor_pre1996$pv),
                   cbind(labor_pre1992$coef, labor_pre1992$ci, sum(labor_pre1992$N), "1977-1988", labor_pre1992$pv))
long_term <- as.data.frame(long_term) %>% 
  slice(3,6,9,12,15,18,21,24,27,30,33,36,39,42,45) %>% 
  rename(.,
         low = "CI Lower",
         high = "CI Upper") %>% 
  mutate(.,
         low = as.numeric(low),
         high = as.numeric(high), 
         Years = as.character(V5), 
         Coeff = as.numeric(Coeff))


is.numeric(long_term$Coeff)


# Plot Placebo
ggplot(long_term, aes(x = V5, y = Coeff)) +
  geom_hline(yintercept = 0, color = "gray50", linetype = 2, size = 0.2) +
  geom_pointrange(aes(ymin = low, ymax = high), color = "dodgerblue4") +
  ylim(-.35,.14)+
  scale_fill_manual(values =  c("dodgerblue2")) +
  annotate("text", x = 1:11, y = -0.337, 
           label = c(#"N = 4,809","5,967", 
             "N = 7,166", 
             "8,239","9,298",
             "10,234","11,164", "11,974","12,881", "13,653",
             "14,821", "15,875", "16,962"),
           color = "gray30", size = 2.8) +
  annotate("text", x = 1:11, y = 0.13, 
           label = c(#"p = 0.97","0.41", 
             "p = 0.30", 
             "0.16","0.06",
             "0.10", "0.12","0.09", "0.12",
             "0.09", "0.09", "0.07", "0.03"),        
           color = "gray30", size = 2.8) +
  labs(x = "Election Years Included in RDD",
       y = "RD Effect on Support for Labor") +
  theme(panel.grid.major = element_blank(), 
        axis.text.x = element_text(size = 8, angle = 90),
        plot.caption = element_text(size = 10, family = "Times",hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))
